#include <bits/stdc++.h>
using namespace std;

#define ONLINE_JUDGE

#ifndef ONLINE_JUDGE
#define dbg(x...) { cerr << "\033[32;1m" << #x << " -> "; err(x); }
void err() { cerr << "\033[39;0m" << endl; }
template<typename T, typename... A>
void err(T a, A... x) { cerr << a << ' '; err(x...); }
#else
#define dbg(...)
#endif

typedef long long LL;

const int N = 1e5+50;

int a[N];
int t, p, n;

int s[N];
int main(int argc, char const *argv[])
{
	scanf("%d", &t);
	for (int kk=0; kk<t; ++kk)
	{
		scanf("%d%d", &n, &p);
		for (int i=0; i<n; ++i)
		{
			scanf("%d", &a[i]);
		}
		
		sort(a, a+n);
		s[0] = a[0];
		for (int i=1; i<n; ++i)
			s[i] = s[i-1] + a[i];
		int ans = 2e9;
		dbg(n, p);
		for (int i=0; i<=n-p; ++i)
		{
			int tot = p * a[i+p-1] - (s[i+p-1]-(i>0? s[i-1]:0));
			dbg(tot);
			ans = min(ans, tot);
		}
		printf("Case #%d: %d\n", kk+1, ans);
	}
	return 0;
}